use uuid::Uuid;

use crate::domain::form::user::CreateUserForm;

#[derive(Clone, Debug, Default)]
pub struct CreateUserParam {
    pub no: Option<String>,
    pub name: Option<String>,
    pub real_name: Option<String>,
    pub nickname: Option<String>,
    pub role_types: Option<String>,
    pub inner_types: Option<String>,
    pub gender: i16,
    pub phone: Option<String>,
    pub avatar_path: Option<String>,
    pub email: Option<String>,
    pub data_source_id: Option<Uuid>,
    pub password: Option<String>,
    pub is_authed: Option<bool>,
    pub is_enabled: Option<bool>,
}

impl CreateUserParam {
    pub fn by_create_form(form: &CreateUserForm) -> Self {
        Self {
            no: form.no.clone(),
            name: form.name.clone(),
            real_name: form.real_name.clone(),
            nickname: form.nickname.clone(),
            role_types: form.role_types.clone(),
            inner_types: form.inner_types.clone(),
            gender: form.gender,
            phone: form.phone.clone(),
            avatar_path: form.avatar_path.clone(),
            email: form.email.clone(),
            data_source_id: form.data_source_id.clone(),
            password: form.new_password.clone(),
            is_authed: form.is_authed.clone(),
            is_enabled: Some(true),
        }
    }
}

impl From<CreateUserForm> for CreateUserParam {
    fn from(form: CreateUserForm) -> Self {
        Self::by_create_form(&form)
    }
}

impl From<&CreateUserForm> for CreateUserParam {
    fn from(form: &CreateUserForm) -> Self {
        Self::by_create_form(form)
    }
}
